package br.com.dispositivosmoveis.acompanhamentodeconta.ui.activity;

import java.util.Arrays;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import br.com.dispositivosmoveis.acompanhamentodeconta.R;

public class MenuListActivity extends ListActivity implements OnItemClickListener {
	
	public static final String MENU_NEW = "Inserir Comanda";
	public static final String MENU_CONSULT = "Consultar Comanda";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_menu_list);
		
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, this.getListMenu()));
		ListView listView = this.getListView();
		listView.setOnItemClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_list, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		TextView textView = (TextView) view;
		
		if(textView.getText().equals(MENU_NEW)){
			this.startActivity(new Intent(this,InserirComandaActivity.class));
		}
		
//		Toast.makeText(getApplicationContext(), msg,
//				Toast.LENGTH_SHORT).show();
	}
	
	private List<String> getListMenu(){
		return Arrays.asList(MENU_NEW, MENU_CONSULT);
	}
}
